n= int(input())
if not(999<n<10000):
    print(0)
    exit()
n = str(n)
sp = []
n1,n2,n3,n4 = n[0],n[1],n[2],n[3]
a =[n1,n2,n3,n4 ,n1 +n2,n2+n3,n3+n4,n1+n2+n3,n2+n3+n4,n1+n2+n3+n4]
for i in a:
    fl = True
    i = int(i)
    for j in range(2,i):
        if i %  j ==0:
            fl = False
            break
    if fl ==1:
        sp.append(i)
if len(sp)==0:
    print(0)
    exit()
else:
    print(max(sp))